package com.qiaoan.back.dao.sys;

import com.qiaoan.back.dao.SqlMapper;
import com.qiaoan.back.model.sys.MenuModel;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created by eversec on 2017/5/11.
 */

@Repository
public interface MenuDao extends SqlMapper {
    /**
     *
     * @param menu
     * @return
     */
    @Insert("insert into t_menu(menu_name, url, pid, role_id, enable, type, level, create_id) values(#{menu_name}, #{url}, #{pid}," +
            "#{role_id}, #{enable}, #{type}, #{level}, #{create_id})")
    int insert(MenuModel menu);

    @Delete("delete from t_menu where id = #{id}")
    public int deleteById(int id);

    @Update("update t_menu set menu_name = #{menu_name}, url = #{url}, pid = #{pid}, role_id = #{role_id}, enable = #{enable}, type = #{type}, type = #{type}, level = #{level}, " +
            "update_time = #{update_time}, update_id = #{update_id} where id = #{id}")
    public int update(MenuModel user);

    @Select("select * from t_menu where id = #{id}")
    public MenuModel getMenuById(int id);

    @Select("select * from t_menu")
    public List<MenuModel> getAllUsers();

    @Select("select * from t_menu where pid = #{pid}")
    List<MenuModel> getchildByPid(int pid);


    /**
     * 根据id获取父菜单和子菜单
     * @param id
     * @return
     */
    List<MenuModel> getParentAndChildMenus(int id);

    @Select("SELECT * FROM t_menu ORDER BY create_time DESC")
    List<MenuModel> getMenusList();
}
